package com.adb.androidwebalbum.uc;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.adb.androidwebalbum.R;
import com.adb.androidwebalbum.utils.Const;

public class ApplicationTopBar extends RelativeLayout implements OnClickListener{

	public TextView txtPageTitle;
	private ImageView menu_refresh;
	private ProgressBar menu_progressbar;
	private OnHeadNavigationSelectedListener mcallback;
	
	public ApplicationTopBar(Context context) {
		super(context);
		init();
	}

	public ApplicationTopBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}
	
	public ApplicationTopBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}
	
	public void init(){
		View view = LayoutInflater.from(Const.CONTEXT).inflate(R.layout.application_topbar,this,true);
		txtPageTitle = (TextView)view.findViewById(R.id.textView_topText);
		menu_refresh = (ImageView)view.findViewById(R.id.menu_refresh);
		menu_refresh.setOnClickListener(this);
		menu_progressbar = (ProgressBar)view.findViewById(R.id.menu_progressbar);
		mcallback = (OnHeadNavigationSelectedListener)Const.CONTEXT;
	}
	
	public void setAppTopBarText(String strTopBar){
		if(strTopBar != null){
			if(txtPageTitle != null){
				txtPageTitle.setText(new StringBuilder(strTopBar));
			}
			
		}
	}
	
	
	public void makeIndeterminateProgressStart(){
		
		if(menu_refresh != null){
			menu_refresh.setVisibility(View.INVISIBLE);
			menu_progressbar.setVisibility(View.VISIBLE);
		}
	}
	public void makeIndeterminateProgressStop(){
		
		if(menu_refresh != null){
			menu_refresh.setVisibility(View.VISIBLE);
			menu_progressbar.setVisibility(View.INVISIBLE);
		}
	}
	public void hideTopLeft(){
		
		if(menu_refresh != null){
			menu_refresh.setVisibility(View.INVISIBLE);
			menu_progressbar.setVisibility(View.INVISIBLE);
		}
	}
	public void onClick(View v) {
		mcallback.onButtonSelected(v.getId());
	}

	
}
